package com.mentaleye.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.dal.dao.LoanRecordDao;
import com.mentaleye.dal.model.LoanRecord;
import com.mentaleye.dal.model.LoanRecordExample;
import com.mentaleye.dal.model.LoanRecordExample.Criteria;
import com.mentaleye.service.LoanRecordService;

@Service
public class LoanRecordServiceImpl implements LoanRecordService {

	@Autowired private LoanRecordDao recordDao;
	
	@Override
	public boolean insertRecord(LoanRecord record) {
		return this.recordDao.insertRecord(record);
	}

	@Override
	public boolean updateRecord(LoanRecord record) {
		LoanRecordExample example=new LoanRecordExample();
		Criteria criteria = example.createCriteria();
		criteria.andRecordIdEqualTo(record.getRecordId());
		return this.recordDao.updateByExample(record, example);
	}

	@Override
	public List<LoanRecord> getList() {
		LoanRecordExample example=new LoanRecordExample();
		return this.recordDao.getListByExample(example);
	}

	@Override
	public List<Map<String, Object>> getListByMap(Map<String, Object> map) {
		return this.recordDao.getListByMap(map);
	}

	@Override
	public boolean deleteByKey(long recordId) {
		LoanRecordExample example=new LoanRecordExample();
		Criteria criteria = example.createCriteria();
		criteria.andRecordIdEqualTo(recordId);
		return this.recordDao.deleteByExample(example);
	}

	@Override
	public LoanRecord getRecordById(long recordId) {
		LoanRecord record=null;
		LoanRecordExample example=new LoanRecordExample();
		Criteria criteria = example.createCriteria();
		criteria.andRecordIdEqualTo(recordId);
		List<LoanRecord> recordList = this.recordDao.getListByExample(example);
		if(!recordList.isEmpty()){
			record=recordList.get(0);
		}
		return record;
	}

}
